#include<stdio.h>
#include<stdlib.h>

#define MAXSIZE 100
typedef int ELemType;
typedef struct Node{
  ELemType data;
  struct Node *next;
}QueueNode;

typedef struct{
  QueueNode *front;
  QueueNode *rear;
}Queue;

Queue* initQueue(){
  Queue *q=(Queue*)malloc(sizeof(Queue));
  QueueNode *node=(QueueNode*)malloc(sizeof(QueueNode));
  node->data=0;
  node->next=NULL;
  q->front=node;
  q->rear=node;
  return q;
}

int isEmpty(Queue *Q){
  if(Q->front==Q->rear){
    printf("队列为空\n");
    return 1;
  }
  return 0;
}

//出队
int dequeue(Queue *Q,ELemType *e){
  QueueNode *node=Q->front->next;
  *e=node->data;
  Q->front->next=node->next;
  if(Q->rear==node) Q->rear=Q->front;
  free(node);
  return 1;
}

//入队
void equeue(Queue *Q,ELemType e){
  QueueNode *node=(QueueNode*)malloc(sizeof(QueueNode));
  node->data=e;
  node->next=NULL;
  Q->rear->next=node;
  Q->rear=node;
}

//获取队头
int getHead(Queue *Q,ELemType *e){
  if(Q->front==Q->rear) return 0;
  *e=Q->front->next->data;
  return 1;
}

int main(){
  Queue *q = initQueue();

	equeue(q, 10);
	equeue(q, 20);
	equeue(q, 30);
	equeue(q, 40);
	equeue(q, 50);
	
	ELemType e;
	dequeue(q, &e);
	printf("出队%d\n",e);
	dequeue(q, &e);
	printf("出队%d\n",e);
	
	getHead(q, &e);
	printf("%d\n",e);

	return 0;
}

